package com.funsport.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.funsport.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * 角色Mapper
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    
    /**
     * 根据用户ID获取角色列表
     */
    @Select("SELECT r.* FROM tb_role r " +
            "INNER JOIN tb_user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<Role> selectByUserId(Long userId);
    
    /**
     * 根据角色编码获取角色
     */
    @Select("SELECT * FROM tb_role WHERE code = #{code}")
    Role selectByCode(String code);
}

